package com.fudan.backend.controller;

import com.fudan.backend.exception.RetCode;
import com.fudan.backend.pojo.StoreOpenRequest;
import com.fudan.backend.pojo.StoreParticipateInActivityRequest;
import com.fudan.backend.service.StoreParticipateInActivityRequestService;
import com.fudan.backend.util.JwtUtil;
import com.fudan.backend.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/activity")
public class StoreParticipateInActivityRequestController {
    @Autowired
    private StoreParticipateInActivityRequestService storeParticipateInActivityRequestService;

    @PostMapping("/participate-request")
    public R addStoreParticipateInActivityRequest(@RequestBody StoreParticipateInActivityRequest storeParticipateInActivityRequest, @RequestHeader String token){
        String userId = JwtUtil.getUserId(token);
        RetCode retCode = storeParticipateInActivityRequestService.addStoreParticipateInActivityRequest(storeParticipateInActivityRequest, userId);
        return new R(retCode);
    }

    @GetMapping("/participate-request/{storeParticipateInActivityRequestId}")
    public R getStoreParticipateInActivityRequestById(@PathVariable("storeParticipateInActivityRequestId") String storeParticipateInActivityRequestId){
        StoreParticipateInActivityRequest storeParticipateInActivityRequest = storeParticipateInActivityRequestService.getStoreParticipateInActivityRequestById(storeParticipateInActivityRequestId);
        return new R(RetCode.ACTIVITY_SUCCESS, storeParticipateInActivityRequest);
    }

    @GetMapping("/participate-request")
    public R getAllStoreParticipateInActivityRequest(int current, int size) {
        PageInfo<StoreParticipateInActivityRequest> page = storeParticipateInActivityRequestService.getAllStoreParticipateInActivityRequest(current, size);
        HashMap<String, Object> map = new HashMap<>();
        map.put("activityRequestList", page.getList());
        map.put("total", page.getTotal());
        return new R(RetCode.ACTIVITY_SUCCESS, map);
    }

    @GetMapping("/participate-request/store/{storeId}")
    public R getAllStoreParticipateInActivityRequestByStoreId(int current, int size, @PathVariable("storeId") String storeId) {
        PageInfo<StoreParticipateInActivityRequest> page = storeParticipateInActivityRequestService.getAllStoreParticipateInActivityRequestByStoreId(current, size, storeId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("activityRequestList", page.getList());
        map.put("total", page.getTotal());
        return new R(RetCode.ACTIVITY_SUCCESS, map);
    }

    @PostMapping("/participate-request/process")
    public R processStoreParticipateInActivityRequest(@RequestBody StoreParticipateInActivityRequest storeParticipateInActivityRequest){
        RetCode retCode = storeParticipateInActivityRequestService.processStoreParticipateInActivityRequest(storeParticipateInActivityRequest);
        return new R(retCode);
    }
}
